//index.js
//获取应用实例
var app = getApp()
var cityInfo = wx.getStorageSync('cityInfo')
Page({
  data: {
    motto: 'Hello World',
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    navigation:[{"title":"航导航A","imgSrc":"images/cate1.png"},{"title":"航导航B","imgSrc":"images/cate2.png"},{"title":"航导航C","imgSrc":"images/cate3.png"},{"title":"航导航D","imgSrc":"images/cate4.png"}],
    userInfo: {},
    city:cityInfo.city
  },
  goToSearch:function(){
    wx.navigateTo({
      url: '../search/index'
    })
  },
  taptest:function(){
    wx.navigateTo({
      url: '../cityList/index'
    })
  },
  /*手动定位*/
  currentPosition:function(){
    wx.showToast({
      title: '定位中',
      icon: 'loading',
      duration: 10000
    })
    var that = this
    app.getCrtLoc(function(city){
      that.setData({
        city:city
      })
    })
    setTimeout(function(){
      wx.hideToast()
    },2000)
  },
  goodsDetail:function(event){
    var goodsId = event.currentTarget.dataset.id
    wx.setStorageSync('goodsId', goodsId)
    var url = '../selcity/index?goodsId='+goodsId;
     wx.navigateTo({
      url: url
    })

  },
  onLoad: function () {
    console.log('onLoad函数开始执行')
    app.getCrtLoc()
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
      console.log('用户数据存入当前页面');
    })

    var pageInfo = {"pos":"index","content":""}
    app.sendReq(function(pageInfo){
      that.setData({
        pageInfo:pageInfo
      })
    })
  }
})
